package com.gk.javaservice.util;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

public class MD5Encryption {
    public static String encryption(String password,int hashIterations,String username,String hashAlgorithName){

        // 用户名
       // String username = "";
        // 用户密码
       // String password = "123456";
        // 加密方式
       // String hashAlgorithName = "MD5";
        // 加密次数
        //int hashIterations = 1;

        if(username==null){
            username="";
        }

        if(hashAlgorithName==null){
            hashAlgorithName = "MD5";
        }

        //使用用户名作为加密盐
        ByteSource credentialsSalt = ByteSource.Util.bytes(username);


        return new SimpleHash(hashAlgorithName, password,
                credentialsSalt, hashIterations)+"";
    }
}
